﻿(function () {
    'use strict';

    var controllerId = 'registerController';

    angular.module('app').controller(controllerId,
        ['$scope', 'registerServece', registerController]);

    function registerController($scope, registerServece) {
        $scope.submit = function () {
            var userName = $scope.userName;
            var password = $scope.password;
            var confirmPassword = $scope.confirmPassword;

            var boolPasswordLength = password.length < 6;
            var boolUsernameLength = userName.length < 6;

            if (boolPasswordLength) {
                alert("password must be at least 6 letters");
                return;
            }

            if (boolUsernameLength) {
                alert("username must be at least 6 letters");
                return;
            }

            if (password != confirmPassword) {
                alert("passwords do not match");
                return;
            } else {
                registerServece.registerUser(userName,password,confirmPassword);
            }
        };
    }
})();
